<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Residency Page
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/expand.css">
	</head>
	<body>
	<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		<div class="message"></div>
		<%
			try {	
		
			/*** Get applicant object ***/
		
			Applicant a = (Applicant)session.getAttribute("applicant");
			
 			/*** Get parameters via URL from previous page and store to applicant object ***/
 			
			a.setStreet(request.getParameter("street"));
			a.setCity(request.getParameter("city"));
			a.setZip(Integer.parseInt(request.getParameter("zip")));
			a.setAreaCode(Integer.parseInt(request.getParameter("areaCode")));
			a.setNumber(Integer.parseInt(request.getParameter("number")));
			
			/*** Determin whether 'state' or 'country phone code' needs to be stored
			 	 in the session object ***/
			
			if(a.getCountryOfResidence().equals("United States"))
			{
				a.setState(request.getParameter("state"));
			}
			else
			{
				a.setCountryPhoneCode(request.getParameter("countryPhoneCode"));
			}
		
			
			/** Write applicant object and degree list to session object **/
			
			session.setAttribute("applicant", a);
			
			ArrayList<Degree> dAl = new ArrayList<Degree>();
			session.setAttribute("degrees", dAl);
			
			/*** Determine whether applicant is citizen of the US and can be directly
				 transfered to the 'provide degree - choose location page' or whether
				 he or she need to fill out the form on this page ***/
			
			if(a.getCountryOfCitizenship().equals("United States"))
			{
				response.sendRedirect("provideDegree/chooseLocation.jsp");
			}
			else
			{
			
		%>
			
		<h2>Previous Data:</h2>
		
		<ol class="tree">
			<li><label for="general">General Information</label><input type="checkbox" id="general" />
				<ol> 
					<li>	
						<table>	
							<tr><td>First Name:</td><td><%= a.getFirstName() %></td></tr>
							<tr><td>Middle Initial:</td><td><%= a.getMiddleInitial() %></td></tr>
							<tr><td>Last Name:</td><td><%= a.getName() %></td></tr>
							<tr><td>Country of Citizenship:</td><td><%= a.getCountryOfCitizenship() %></td></tr>
							<tr><td>Country of Residence:</td><td><%= a.getCountryOfResidence() %></td></tr>
							<tr><td>Street:</td><td><%= a.getStreet() %></td></tr>
							<tr><td>City:</td><td><%= a.getCity() %></td></tr>
							<tr><td>ZIP/Postal Code:</td><td><%= a.getZip() %></td></tr>
						<%	
							/*** Determin whether 'state' or 'country phone code' needs to be displayed ***/
						
							if(a.getCountryOfResidence().equals("United States"))
							{
								out.print("<tr><td>State:</td><td>" + a.getState() + "</td></tr>");
							}	
							else
							{
								out.print("<tr><td>Country Phone Code:</td><td>" + a.getCountryPhoneCode() + "</td></tr>");
							}
						%>
							<tr><td>Area code:</td><td><%= a.getAreaCode() %></td></tr>
							<tr><td>Number:</td><td><%= a.getNumber() %></td></tr>
						</table>
					</li>
				</ol>
			</li>
		</ol>
		<hr>
		<br>
		<%
			}
		%>
				<form method="GET" action="provideDegree/chooseLocation.jsp">
					<table>
						<tr><td>US permanent residence:</td>
							<td><input type="radio" name="usResidence" value="true"></td>
						</tr>
						<tr><td>Non US permanent residence:</td>
							<td><input type="radio" name="usResidence" value="false"></td>
						</tr>
					</table>
					<input type="submit" value="Submit">
				</form>
				<%
					}
					catch(Exception e)
					{
						response.sendRedirect(BASE + "error.jsp");
					}
				%>
			</div>
		</body>
	</html>